package com.longge;

import java.util.PriorityQueue;
import java.util.Queue;

public class PickGifts {

    public long pickGifts(int[] gifts, int k) {
        Queue<Integer> pq = new PriorityQueue<>((o1, o2) -> o2 - o1);

        for (int gift : gifts) {
            pq.offer(gift);
        }

        while (k != 0) {
            k--;
            Integer maxGift = pq.poll();
            pq.offer((int) Math.sqrt(maxGift));
        }
        long ans = 0;
        while (!pq.isEmpty()) {
            ans += pq.poll();
        }
        return ans;


    }
}
